package com.yxzr.youyou.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yxzr.youyou.R;

public class EarnPointsAdapter extends RecyclerView.Adapter<EarnPointsAdapter.ViewHolder> {
    private Context mContext;
    private int selectIndex = 1;
    public EarnPointsAdapter(Context context){
        this.mContext = context;
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ViewHolder viewHolder = new ViewHolder(LayoutInflater.from(mContext).inflate(R.layout.earnpoints_adapter_layout,parent,false));
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        if (position < selectIndex){
            holder.earnpoints_adapter_img.setVisibility(View.VISIBLE);
            holder.earnpoints_adapter_linear.setBackgroundResource(R.drawable.type_text_shape);
            holder.earnpoints_adapter_day.setTextColor(Color.parseColor("#ffffff"));
        }else {
            holder.earnpoints_adapter_img.setVisibility(View.GONE);
            holder.earnpoints_adapter_linear.setBackgroundResource(R.drawable.gray_btn_shape);
            holder.earnpoints_adapter_day.setTextColor(Color.parseColor("#666666"));
        }

        holder.earnpoints_adapter_day.setText("第"+(position+1)+"天");

        if (position == 0){
            holder.earnpoints_adapter_score.setText("20  积分");
        }else if(position == 1){
            holder.earnpoints_adapter_score.setText("30  积分");
        }else if(position == 2){
            holder.earnpoints_adapter_score.setText("40  积分");
        }else if(position == 3){
            holder.earnpoints_adapter_score.setText("50  积分");
        }else if(position == 4){
            holder.earnpoints_adapter_score.setText("60  积分");
        }else if(position == 5){
            holder.earnpoints_adapter_score.setText("70  积分");
        }else {
            holder.earnpoints_adapter_score.setText("100  积分");
        }
    }

    @Override
    public int getItemCount() {
        return 7;
    }

    public void setSelectIndex(int pos){
        this.selectIndex = pos;
        notifyDataSetChanged();
    }

    class ViewHolder extends RecyclerView.ViewHolder{
        private ImageView earnpoints_adapter_img;
        private LinearLayout earnpoints_adapter_linear;
        private TextView earnpoints_adapter_day,earnpoints_adapter_score;
        public ViewHolder(View itemView) {
            super(itemView);
            earnpoints_adapter_img = itemView.findViewById(R.id.earnpoints_adapter_img);
            earnpoints_adapter_linear = itemView.findViewById(R.id.earnpoints_adapter_linear);
            earnpoints_adapter_day = itemView.findViewById(R.id.earnpoints_adapter_day);
            earnpoints_adapter_score = itemView.findViewById(R.id.earnpoints_adapter_score);
        }
    }
}
